package com.young.shop.controller;

import com.young.shop.pojo.entity.User;
import com.young.shop.service.UserService;
import com.young.shop.service.impl.UserServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/changePass")
public class ChangePasswordController extends BaseController {
    private UserService userService=new UserServiceImple();
    @Override
    protected void doGet(HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        //得到登录的对象
        User user = (User)req.getSession().getAttribute("client");

        //得到前端的参数
        //判断密码是否正确
        //判断修改密码的两次值是都一样
        //修改数据库
        try{
            User dbUser = userService.changePassword(req , user);
            writerSucccessBaseRespVoToResponse(resp,dbUser);
        }catch (RuntimeException e){
            writerFailedBaseRespVoToResponse(resp,e);
        }
    }
}
